# coding=utf-8
# 代码文件：chapter5/ch5.4.5.py

import pandas as pd
from sqlalchemy import create_engine

# 创建sqlalchemy数据库引擎
engine = create_engine('sqlite:///data/db/QuoteDB.db')
#  无参数查询
df = pd.read_sql_query('SELECT * FROM HistoricalQuote', engine, parse_dates=['HDate'])

# print(df)

# 股票代号参数
paramlist = [600519]
#  有条件参数查询
df = pd.read_sql_query('SELECT * FROM HistoricalQuote  where Symbol = ?', engine,
                       parse_dates=['HDate'],
                       params=paramlist)

f = r'data/temp.csv'            # csv文件路径

df.to_csv(f, encoding='gbk')    # 将df对象内容输出到temp.csv文件中

print('Game Over')
